<?php
namespace Admin\Controller;
use Think\Controller;
class RoleController extends CommonController {

    public function index() {
        $Role = M("Role");
        $list = $Role->select();
        $this->assign("list", $list);
        $this->display('role');
    }


    public function add() {
        $M = M('Role');
        if (IS_POST) {
            $id = I('post.id');
            $data = array();
            $data['name'] = I('post.name');
            $data['status'] = I('post.status');
            $data['sort'] = I('post.sort');
            $data['remark'] = I('post.remark');

            $data['update_time'] = NOW_TIME;
            if($id){
                $data['id'] = $id;
                $M->save($data);
            }else{
                $data['create_time'] = NOW_TIME;
                $M->add($data);
            }
            $result = array('status' => 1, 'info' => "操作成功！", 'url' => U("Access/roleList"));
            $this->ajaxReturn($result);
        }

        $id = I('get.id');
        if($id){
            $info = $M->where('id='.$id)->find();
            $this->assign('info',$info);
        }
        $this->display("add");
    }

    public function del(){
        $id = I('get.id');
        $M = M('Role');
        $M->where( array('id'=>$id) )->delete();
        $this->success('操作成功！');
    }



}